<?xml version="1.0" encoding="UTF-8" ?>
 
<xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns="http://www.w3.org/1999/xhtml">
    <xsl:output method="xml" indent="no"
        doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>

<xsl:include href="../../../templates/root.xsl"/>
<xsl:include href="../../../templates/date_selector.xsl"/>
<xsl:include href="report_selector.xsl"/>

<xsl:template match="*"/>

<xsl:template match="report_name">
    <xsl:call-template name="reportSelector"/>
    <xsl:call-template name="dateSelector"/>
    <h1><xsl:value-of select="."/></h1>
</xsl:template>

<xsl:template match="report_data">
    <input type="hidden" id="showMoreDate1" value="{/root/date1}"/>
    <input type="hidden" id="showMoreDate2" value="{/root/date2}"/>
    <script src="design/append_table.js" type="text/javascript"/>
    <script src="design/httprequest.js" type="text/javascript"/>
    <script type="text/javascript">
        <xsl:comment>
        <![CDATA[
        function onExpandData(data, to, row, a)
        {
            var from = data.getElementsByTagName('table');
            if (from.length > 0) {
                var count = insertTable(from.item(0), to, row.rowIndex);
                a.parentElement.replaceChild(document.createTextNode(a.innerHTML), a);
            }
        }
        function onExpandError(text)
        {
            alert(text);
        }
        function expandDir(a, dir)
        {
            var to = document.getElementById('reportTable');
            if (to) {
                var row = to.rows.namedItem('dir'+dir);
                if (row) {
                    a.removeAttribute('href');
                    a.removeAttribute('onclick');
                    a.className = 'expandprocess';

                    var params = 'module=popularity&report=dirs_expand';
                    params += '&date1='+document.getElementById('showMoreDate1').value;
                    params += '&date2='+document.getElementById('showMoreDate2').value;
                    params += '&dirs='+dir;
                    httpRequest('report.php', params, function(data){onExpandData(data, to, row, a);}, onExpandError, {'asHTML': true});
                }
            }
            return false;
        }
        ]]>
        </xsl:comment>
    </script>
    <table class="reportTable" id="reportTable">
        <tr>
            <th>Путь</th>
            <th>Просмотров</th>
        </tr>
        <xsl:apply-templates select="row"/>
    </table>
</xsl:template>

<xsl:template match="row[@subDirs=0]">
        <tr>
            <td style="text-align: left;"><xsl:value-of select="@dirName"/></td>
            <td><a href="report.php?module=popularity&amp;report=links&amp;date1={/root/date1}&amp;date2={/root/date2}&amp;dirs={@dirId}"><xsl:value-of select="@summ"/></a></td>
        </tr>
</xsl:template>

<xsl:template match="row[@subDirs=1]">
        <tr id="dir{@dirId}">
            <td style="text-align: left;"><a href="#" onclick="return expandDir(this, '{@dirId}');" class="expand"><xsl:value-of select="@dirName"/></a></td>
            <td><a href="report.php?module=popularity&amp;report=links&amp;date1={/root/date1}&amp;date2={/root/date2}&amp;dirs={@dirId}"><xsl:value-of select="@summ"/></a></td>
        </tr>
</xsl:template>


</xsl:stylesheet>